import { http } from "@/utils/request";
import {
  PATHTYPE,
  type ProjectSearchRequest,
  type ProjectVo,
} from "@/interface/project.ts";
import type { ProjectTitleStats } from "@/api/project.ts";
const baseUrl = "";

/**
 * @description 单项目-任务树
 */
export const getTaskList = (params: any): Promise<any> => {
  return http.post(`${baseUrl}/task/list`, params);
};

/**
 * @description 单项目-任务树
 */
export const getTaskListTree = (params: any): Promise<any> => {
  return http.post(`${baseUrl}/task/tree`, params);
};

/**
 * @description 单项目-任务列表-详情
 */
export const getTaskDetail = (id: string): Promise<any> => {
  return http.get(`${baseUrl}/task/${id}`);
};

/**
 * @description 单项目-任务列表-详情
 */
export const getTaskDetailTitle = (taskId: string): Promise<any> => {
  return http.get(`${baseUrl}/task/taskTabTitle/${taskId}`);
};

/**
 * @description 单项目-修改任务
 */
export const editTask = (params: any): Promise<any> => {
  return http.put(`${baseUrl}/task/edit`, params);
};

/**
 * @description 单项目-任务-详情-评论-发布
 */
export const saveComment = (params: any): Promise<any> => {
  return http.put(`${baseUrl}/reply/create`, params);
};

/**
 * @description 单项目-任务-详情-评论-列表
 */
export const getReplyList = (params: any): Promise<any> => {
  return http.post(`${baseUrl}/reply/list`, params);
};

/**
 * @description 单项目-任务-详情-评论-删除
 */
export const deleteComment = (commentId: string): Promise<any> => {
  return http.delete(`${baseUrl}/reply/${commentId}`);
};

/**
 * @description 单项目-修改任务
 */
export const deleteTaskRelation = (params: any): Promise<any> => {
  return http.put(`${baseUrl}/task/drag`, params);
};

/**
 * @description 单项目-任务-文件列表：参考资料/输入数据/输出数据/交付物
 */
export const getItemsList = (params: any): Promise<any> => {
  return http.post(`${baseUrl}/dataflowFile/list`, params);
};

/**
 * @description 单项目-任务-文件删除：参考资料/输入数据/输出数据/交付物
 */
export const deleteItem = (id: string): Promise<any> => {
  return http.delete(`${baseUrl}/dataflowFile/${id}`);
};

/**
 * @description 单项目-任务-文件编辑：参考资料/输入数据/输出数据/交付物
 */
export const editItem = (params: any): Promise<any> => {
  return http.put(`${baseUrl}/dataflowFile/edit`, params);
};

/**
 * @description 触发迁移
 */
export const checkChangeState = (
  type: string,
  dataId: string,
  edgeId: string,
): Promise<any> => {
  return http.post(
    `${baseUrl}/lifeCycleExecution/transfer/${type}/${dataId}/${edgeId}`,
    {},
  );
};

/**
 * @description 单项目-新增任务
 */
export const taskCreate = (params: any): Promise<any> => {
  return http.post(`${baseUrl}/task/create`, params);
};

/**
 * @description 单项目-修改任务
 */
export const taskEdit = (params: any): Promise<any> => {
  return http.put(`${baseUrl}/task/edit`, params);
};

/**
 * @description 单项目-任务列表-详情
 */
export const getBaseDataConfig = (targetType: string): Promise<any> => {
  return http.get(
    `${baseUrl}/baseDataConfigEntity/getByTargetType/${targetType}`,
  );
};

/**
 * @description 单项目-任务-文件列表：文档中心文件列表
 */
export const getDocCenterList = (params: any): Promise<any> => {
  return http.post(`${baseUrl}/sdm/docCenter/list`, params);
};

/**
 * @description 全局设置-任务类型-详情
 */
export const getTaskTypeList = (params: any): Promise<any> => {
  return http.post(`${baseUrl}/taskType/list`, params);
};

/**
 * @description 项目管理-项目成员列表-分角色tab
 */
export const getProjectRoleUserList = (
  projectId: string,
  roleIdOrAll: string,
  params: any,
): Promise<any> => {
  return http.post(
    `${baseUrl}/projectRoleUser/tab/${projectId}/${roleIdOrAll}`,
    params,
  );
};

/**
 * @description 文件上传
 */
export const uploadFile = (params: any): Promise<any> => {
  return http.post(`${baseUrl}/dataflowFile/create`, params);
};

/**
 * @description 单项目-文件列表
 */
export const getTaskSimpleTree = (params: any): Promise<any> => {
  return http.post(`${baseUrl}/task/simpleTree`, params);
};

/**
 * @description 单任务-任务列表-输入数据/输出数据-新建节点
 */
export const createTaskData = (params: any): Promise<any> => {
  return http.post(`${baseUrl}/dataflow/create`, params);
};

/**
 * @description 单项目-任务-打包下载多个文件
 */
export const bathDownLoadTaskFile = (params: any): Promise<any> => {
  return http.post(`${baseUrl}/dataflowFile/packDownload`, params);
};

/**
 * @description 单项目-任务列表-详情-表头计数
 */
export const getTaskCount = (taskId: string): Promise<any> => {
  return http.get(`${baseUrl}/task/taskTabTitle/${taskId}`);
};

/**
 * @description 单任务-任务列表-文件节点和文件
 */
export const getDataTree = (params: any): Promise<any> => {
  return http.post(`${baseUrl}/dataflow/tree`, params);
};

/**
 * @description 单任务-任务列表-输入数据/输出数据-删除
 */
export const deleteDataFlowItem = (id: string): Promise<any> => {
  return http.delete(`${baseUrl}/dataflow/${id}`);
};

/**
 * @description 单任务-任务列表-输入数据/输出数据-更新节点
 */
export const editDataFlow = (params: any): Promise<any> => {
  return http.put(`${baseUrl}/dataflow/edit`, params);
};

/**
 * @description 单项目-任务-文件删除：可以批量删除，文件id逗号分隔，参考资料/输入数据/输出数据/交付物
 */
export const deleteDataFlowBatch = (idList: string): Promise<any> => {
  return http.delete(`${baseUrl}/dataflowFile/all/${idList}`);
};

/**
 * @description 单项目-任务列表-详情-表头计数
 */
export const getPermission = (
  projectId: string,
  permission: string,
): Promise<any> => {
  return http.get(`${baseUrl}/projectRoleUser/has/${projectId}/${permission}`);
};

/**
 * @description 单项目-任务列表-新增任务关系
 */
export const createRelationTask = (params: any): Promise<any> => {
  return http.post(`${baseUrl}/taskRelation/create`, params);
};

/**
 * @description 单项目-任务列表-修改任务关系
 */
export const editRelationTask = (params: any): Promise<any> => {
  return http.put(`${baseUrl}/taskRelation/edit`, params);
};

/**
 * @description 单项目-任务列表-删除任务关系
 */
export const deleteRelationTask = (
  preTaskId: string,
  followTaskId: string,
): Promise<any> => {
  return http.delete(`${baseUrl}/taskRelation/${preTaskId}/${followTaskId}`);
};

/**
 * @description 单项目-任务列表-相关任务2
 */
export const getTaskRelationList = (
  ofTaskId: string,
  params: any,
): Promise<any> => {
  return http.post(`${baseUrl}/taskRelation/list/${ofTaskId}`, params);
};

/**
 * @description 修改任务的父子关系
 */
export const editTaskDrag = (params: any): Promise<any> => {
  return http.put(`${baseUrl}/task/drag`, params);
};
/**
 * @description 我的任务-任务列表
 */
export const listMyTaskTab = (
  params: ProjectSearchRequest,
  types: string[] = [],
): Promise<ProjectVo[]> => {
  const finalTypes = types.length ? types : [PATHTYPE.All];
  const query = finalTypes.map((t) => `type=${t}`).join("&");
  return http.post(`/task/multiTypeTab?${query}`, params);
};
/**
 * @description 我的任务-任务表头统计
 */
export const getMyTaskTitle = (
  params: ProjectSearchRequest,
  types: string[] = [],
): Promise<ProjectTitleStats> => {
  const finalTypes = types.length ? types : [PATHTYPE.All];
  const query = finalTypes.map((t) => `type=${t}`).join("&");
  return http.post(`/task/myTaskTitle?${query}`, params);
};
